/*
*
* bus配置
* */
import busResult from '../../../static/data/bus.json'
import api from '../../api/api'
import ajax from '../../utils/ajax/index'

const bus = {
  namespaced: true,
  state: {
    // 主模块数据
    busResult: busResult, // 初始化数据
    current: 0, // 进度状态
    // busStart数据
    protocolList: {
      protocolTitle: '',
      company: '请输入公司名称',
      companyShort: '请输入公司简称',
      cardName: '请输入电子公交卡片名称',
      telephone: '请输入客服电话'
    },
    helpquestions: []
  },
  mutations: {
    busResult (state, obj) {
      state.busResult = obj
    },
    mutCurrent (state, obj) {
      if (obj === 2) {
        obj = 0
      } else if (obj === 0) {
        obj = 2
      } else {
        obj++
      }
      state.current = obj
      sessionStorage.setItem('current', JSON.stringify(state.current))
    },
    mutHelpquestions (state, obj) {
      state.helpquestions = obj
    }
  },
  actions: {
    busSubmit ({state, commit, dispatch}, obj) { // 提交进程步骤
      if (state.current === 0) {
        ajax.postFile(api.bus.openProgress, obj.params).then((res) => {
          sessionStorage.setItem('dataId', JSON.stringify(res.data))
          obj.mes.success(res.msg.message)
          commit('mutCurrent', state.current)
          sessionStorage.removeItem('openData')
        })
      } else if (state.current === 1) {
        ajax.postFile(api.bus.styleProgress, obj.params).then((res) => {
          obj.mes.success(res.msg.message)
          commit('mutCurrent', state.current)
          sessionStorage.removeItem('styleData')
        })
      } else {
        ajax.postFile(api.bus.openLine, obj.excel).then((res) => {
          obj.mes.success(res.msg.message)
        })
        ajax.postFile(api.bus.menuProgress, obj.params).then((res) => {
          obj.mes.success(res.msg.message)
          commit('mutCurrent', state.current)
          sessionStorage.removeItem('detailData')
        })
      }
    },
    getMenuData ({state, commit}, obj) {
    }
  }
}

export default bus
